﻿@page
@model NoticeClient.Pages.RegisterModel
@{
    ViewData["Title"] = "注册";
}

<header class='notice-header'>
    <h1 class="notice-title">注 册</h1>
</header>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label required">账号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="account" type="text" pattern="[0-9a-zA-Z]*" placeholder="请输入账号">
        </div>
    </div>

    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label required">密码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="pwd" type="password" value=""  placeholder="请输入密码">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label required">确认密码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="pwd2" type="password" value="" placeholder="请再次输入密码">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label required">企业ID</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="CorpId" type="text" placeholder="请输入企业ID">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label required">应用ID</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="AgentId" type="text" placeholder="请输入AgentId">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label required">应用Secret</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="CorpSecret" type="text" placeholder="请输入Secret">
        </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd"><label class="weui-label required">验证码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="code" type="number" placeholder="请输入验证码">
        </div>
        <div class="weui-cell__ft">
            <img class="weui-vcode-img" src="" onclick="clickimg()">
        </div>
    </div>
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:" id="RegisterBtn">注 册</a>
    </div>
</div>

@section Scripts{
    <script type="text/javascript">
        var yzm_id = "";
        clickimg();

        function clickimg() {
            ajax({
                url: "/VerifyCode/NumberVerifyCode",
                contentType: "application/x-www-form-urlencoded",
                dataType: "text",
                success: function (data) {
                    var ss = data.split('###');
                    $(".weui-vcode-img").attr('src', ss[0]);
                    yzm_id = ss[1];
                }
            });
        }

        $("#RegisterBtn").click(function () {
            var d = {
                "account": $("#account").val(),
                "pwd": $("#pwd").val(),
                "corpId": $("#CorpId").val(),
                "agentId": $("#AgentId").val(),
                "corpSecret": $("#CorpSecret").val(),
                "code": $("#code").val(),
                "codeId": yzm_id
            };
            if (IsNullOrEmpty(d.account)) {
                $.toptip("账号不为空", 'error');
                return;
            }
            if (IsNullOrEmpty(d.pwd)) {
                $.toptip("密码不为空", 'error');
                return;
            }
            if (IsNullOrEmpty(d.code)) {
                $.toptip("验证码不为空", 'error');
                return;
            }
            if ($("#pwd2").val() != d.pwd) {
                $.toptip("两次输入的密码不一样", 'error');
                return;
            }
            if (IsNullOrEmpty(d.corpId)) {
                $.toptip("企业ID不为空", 'error');
                return;
            }
            if (IsNullOrEmpty(d.agentId)) {
                $.toptip("应用ID不为空", 'error');
                return;
            }
            if (IsNullOrEmpty(d.corpSecret)) {
                $.toptip("应用Secret不为空", 'error');
                return;
            }
            ajax({
                url: API_Address + "/User/Register",
                data: d,
                success: function (data) {
                    if (data.type == 404) {
                        $.toptip(data.message, 'error');
                    }
                    else if (data.type == 200) {
                        $.toptip(data.message, 'success'); 
                        window.location.href = '/index'
                    }
                }
            });
        })
    </script>
}